import { defineStore } from "pinia";
import { Names } from "../../store-namespace";
import { _get, _post, _put, _delete, http } from "@/utils/axios";
import { ElNotification } from "element-plus"; //处理导航信息
import { ProductionPlan, BomMRoute } from "@/api/backend/index";
import { mapCompanies } from "@/utils/common";

export const useProductionPlan = defineStore(Names.productionPlan, {
  state: () => {
    return {
      planId: 0, //工艺路线查询的生产计划id
      options: <any>{},
      single: {
        code: "20230602141704553",
        createBy: null,
        createTime: null,
        deliverDate: "2023-07-01",
        endTime: "2023-06-30 00:00:00",
        id: 1,
        isProduct: 0,
        isSuspend: 0,
        materialState: "准备中",
        name: "20230602141704553",
        origin: "内部",
        planNum: 12,
        planQuantity: 12.12,
        planState: 0,
        planType: "机加工计划",
        priority: 0,
        processRoute: "[J]-[K]",
        productCode: "BS04-90S-04",
        productName: "900柜二层篮子碗架组件粗坯",
        productNum: 12,
        productQuantity: 12.12,
        productRate: 29,
        productType: 0,
        remark: null,
        startTime: "2023-06-02 00:00:00",
        toolState: "未交接生产",
        updateBy: null,
        updateTime: null,
        workshopId: 1,
        workshopName: "机加车间",
      },
      getPlanOfProcess: {}, //获取到的相关计划的工艺数据
    };
  },
  getters: {},
  actions: {
    //生产计划
    getPlanList(filter: any) {
      return new Promise((resolve, reject) => {
        _get(ProductionPlan + "/list", filter, "json", "").then((res) => {
          console.log("生产计划", res);
          resolve(res);
        });
      });
    },
    //生产计划关于工艺路线 通过计划id获取工艺路线
    getPlanProcessList(filter: any) {
      return new Promise((resolve, reject) => {
        _get(BomMRoute + "/" + filter.id, {}, "json", "").then((res) => {
          console.log("生产计划关于工艺路线", res);
          resolve(res);
        });
      });
    },
    //计划导入excel文件
    importExcel(data: any) {
      return new Promise((resolve, reject) => {
        _post(ProductionPlan + "/import", data, "formData", "")
          .then((res) => {
            console.log("导入excel文件", res);
            resolve(res as any);
          })
          .catch((err) => {
            console.log(err);
          });
      });
    },
  },
});
